const { merge } = require('webpack-merge')
const baseWebpackConfig = require('./webpack.base.config')
//清理插件
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')

module.exports = merge(baseWebpackConfig, {
    mode: 'production', //会自动将 js 代码进行打包
    devtool: false,
    module: {
        rules: [
            {
                test: /\.less$/,
                use: [
                    {
                        loader: MiniCssExtractPlugin.loader,
                        options: {
                            publicPath: '../'
                        }
                    },
                    'css-loader',
                    'less-loader'
                ]
            }
        ]
    },
    watch: true,
    //开启 watch，下面才有意义
    watchOptions: {
        //不监听解析模块目录
        ignored: /node_modules/,
        //防止更新频率太快，默认 300 毫秒，意味监听到变化后 500 毫秒再编译
        aggregateTimeout: 2000,
        //轮询间隔时间，1 秒，询问系统指定文件是否变化了
        poll: 1000
    },
    //插件
    plugins: [
        //清理打包
        new CleanWebpackPlugin(),
        new MiniCssExtractPlugin({
            filename: 'css/[name].css'
        })
    ]
})